#include<bits/stdc++.h>
using namespace std;
vector<int> edges[100005];
int n;
int ans[100005];
int dfs(int cur)
{
	int cnt=1;
	for(auto v:edges[cur])
	{
		cnt+=dfs(v);
	}
	ans[cur]=cnt;
	return cnt;
} 
int main()
{
	int s;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int fa;
		cin>>fa;
		if(fa==0)s=i;
		else
			edges[fa].push_back(i);
	}
	dfs(s);
	for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
	return 0;
}
